<template>
	<view class="container">
		
		<u-navbar title="个人中心"  :border-bottom="false" :is-back="false" title-color="#000000">
			<view class="navbar-right" slot="right" @click="toPage('/pages/user/setting/setting')">
				<u-icon name="setting" size="44"></u-icon>
			</view>
		</u-navbar>
		
		
		<!-- start用户信息 -->
		<!-- 已登录 -->
		<view class="userinfo" v-if="isAuthInfo" @click="toUserInfoPage">
			<view class="userinfo-avatar">
				<u-avatar :src="userInfo.avatar" size="160"></u-avatar>
			</view>
			<view class="userinfo-name">{{userInfo.nickName}}</view>
		</view>

		<!-- 未登录 -->
		<view class="userinfo" v-else @click="toPage('/pages/login/login')">
			<view class="userinfo-avatar">
				<u-avatar size="160"></u-avatar>
			</view>
			<view class="userinfo-name">登录 / 注册</view>
		</view>
		<!-- end用户信息 -->
		
		<!-- start订单 -->
		<view class="menu-list">
			<view class="tit">二手市场</view>
			<view class="procedure">
				<view class="item" @click="toPage('/pages/user/my-publish/my-publish')">
					<image mode="aspectFill" src="/static/images/icon/my-publish.png"></image>
					<text>我发布的</text>
				</view>
				<view class="item" @click="toPage('/pages/user/my-sold/my-sold')">
					<image mode="aspectFill" src="/static/images/icon/my-sell.png"></image>
					<text>我卖出的</text>
				</view>
				<view class="item" @click="toPage('/pages/user/my-buy/my-buy')">
					<image mode="aspectFill" src="/static/images/icon/my-buy.png"></image>
					<text>我买到的</text>
				</view>
				<view class="item" @click="toPage('/pages/user/my-collect/my-collect')">
					<image mode="aspectFill" src="/static/images/icon/collect.png"></image>
					<text>我的收藏</text>
				</view>
			</view>
		</view>
		<!-- end订单 -->
		
		<view class="menu-list">
			<view class="tit">失物招领</view>
			<view class="procedure">
				<view class="item" @click="toPage('/pages/user/my-lost-found/my-lost-found')">
					<image mode="aspectFill" src="/static/images/icon/lost-and-found.png"></image>
					<text>我发布的</text>
				</view>
				<view class="item" @click="toPage('/pages/user/my-lost-found-return/my-lost-found-return')">
					<image mode="aspectFill" src="/static/images/icon/guihuan.png"></image>
					<text>我归还的</text>
				</view>
				<view class="item" @click="toPage('/pages/user/my-lost-found-claim/my-lost-found-claim')">
					<image mode="aspectFill" src="/static/images/icon/lingqu.png"></image>
					<text>我认领的</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { loginByWx, appLoginByQQ } from "@/api/login.js";
	import { constant } from '@/utils/constant.js'
	const app = getApp();

	export default {
		data() {
			return {
				isAuthInfo: false,
				params: {}
			}
		},
		components: {},
		props: {},
		methods: {
			init() {
				let userInfo = uni.getStorageSync(constant.userInfo)
				let token = uni.getStorageSync(constant.tokenKey)
				if (userInfo && token) {
					app.globalData.userInfo = userInfo;
					app.globalData.token = token;
					this.userInfo = userInfo;
					this.isAuthInfo = true;
				} else {
					this.userInfo = {}
					this.isAuthInfo = false;
				}
			},
			// 导航到用户详情页
			toUserInfoPage () {
				console.log(this.userInfo)
				this.$u.route('/pages/user-detail/user-detail', {
					userInfo: encodeURIComponent(JSON.stringify(this.userInfo))
				})
			},
			// 页面跳转
			toPage(url) {
				this.$u.route(url)
			}
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			this.init()
		}
	}
</script>

<style lang="scss">
	@import "./user.scss";
</style>
